#include "gui.h"



gui::gui( QWidget *parent, Qt::WFlags flags ): QMainWindow( parent, flags )
{
	main_w = 0;
	setup_w = 0;
	listener_w = 0;
	main_w = new main_widget( this );
	this->setCentralWidget( main_w );
	this->setMinimumSize( 291, 207 );
	this->resize( 291, 207 );
};



server_gui* server_gui::get_instance()
{
	static server_gui inst(0);
	return &inst;
};



void server_gui::create_gui()
{
	g = new gui();
};



void server_gui::show_network_error( const string& s )
{
	QMessageBox::critical( 0, "Network error", s.c_str() );
};



void server_gui::show_client_status( unsigned int c, const string& s )
{
	if ( g->listener_w != 0 )
	{
		g->listener_w->connected_players[ c ]->set_status( s );
	}
};



void server_gui::show_client_error( unsigned int c, const string& e )
{
	if ( g->listener_w != 0 )
	{
		g->listener_w->connected_players[ c ]->set_error( e );
	}
};



void server_gui::set_client_name( unsigned int c, const string& n, const string& t )
{
	if ( g->listener_w != 0 )
	{
		g->listener_w->connected_players[ c ]->set_name( n, t );
	}
};



void server_gui::show_listener_status( const string& s )
{
	if ( g->listener_w != 0 )
	{
		g->listener_w->show_status( s );
	}
};



void server_gui::show_listener_restart()
{
	if ( g->listener_w != 0 )
	{
		for ( unsigned int i = 0; i < server_listener::get_instance()->server->max_clients; ++i )
		{
			g->listener_w->connected_players[ i ]->set_name( "", "" );
			g->listener_w->connected_players[ i ]->set_status( "Not connected." );
			g->listener_w->connected_players[ i ]->set_error( "No errors." );
		}
	}
};